/**
 * 
 */
package com.antilia.infomaresme.pages.images;

import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;

import com.antilia.infomaresme.data.dao.interfaces.IImageService;
import com.antilia.infomaresme.data.dataobjects.ImageDetail;
import com.antilia.infomaresme.data.dataobjects.Item;
import com.google.inject.Inject;

/**
 * @author Ernesto
 *
 */
public class ImagesPanel extends Panel {

	private static final long serialVersionUID = 1L;

	@Inject
	private IImageService imagesService;
	
	/**
	 * @param id
	 * @param model
	 */
	public ImagesPanel(String id, IModel<Item> model) {
		super(id, model);
		List<ImageDetail> details =imagesService.getImageDetails(model.getObject());
		RepeatingView images = new RepeatingView("images");
		add(images);
		for(final ImageDetail detail: details) {			
			WebMarkupContainer wmc = new WebMarkupContainer(images.newChildId());
			images.add(wmc);
			wmc.add(new AjaxLazyLoadPanel("image") {
				
				private static final long serialVersionUID = 1L;

				@Override
				public Component getLazyLoadComponent(String markupId) {
					return new ImagePanel(markupId, detail);
				}
			});
		}
	}

	public IImageService getImagesService() {
		return imagesService;
	}

	public void setImagesService(IImageService imagesService) {
		this.imagesService = imagesService;
	}



}
